<?php

/**
 * 反射机制
 *
 */
namespace src\abstractDemo;

use ReflectionException;

/**
 * 反射机制 + 配置文件优化 支付类接口
 * Class ReflectFactory
 * @package src\ReflectFactory
 */
class ReflectFactory
{
    private $className;



    public function __construct($payAlis='A')
    {
        $config = file_get_contents( __DIR__ . "/../config.json");
        $data=json_decode($config,true);
        $this->className=$data['namespace'].$data['data'][$payAlis];
    }

    /**
     * @return object
     * @throws ReflectionException
     */
    public function createPay()
    {
        try{
            $class = new \ReflectionClass($this->className);

            $obj = $class->newInstance();
        }catch (ReflectionException  $e){
            throw new ReflectionException($e->getMessage());
        }
        return $obj;
    }
}